{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1.7.1\n"
     ]
    }
   ],
   "source": [
    "print(torch.__version__)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "cpu\n"
     ]
    }
   ],
   "source": [
    "device = torch.device(\"cuda:0\" if torch.cuda.is_available() else \"cpu\")\n",
    "print(device)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import torch.nn as nn\n",
    "import torch\n",
    "import torch.optim as optim\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYIAAAEGCAYAAABo25JHAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/Il7ecAAAACXBIWXMAAAsTAAALEwEAmpwYAAAW6UlEQVR4nO3df5DcdX3H8dcrR5BTqQfkVLwkJjoxikYNcwVqOpUiAjI2pLEqGSxisanT4tjWiU1KCohOg2Z0HEfUBsqoFUFk4vUsYeKP4DgTDc3RA44EowEVcqJEJHQsUS/h3T/2u2Gz2d3bu9vvfr+73+dj5obd7/czt+/bHPu67+fz/Xw+jggBAIprVtYFAACyRRAAQMERBABQcAQBABQcQQAABXdc1gVM1Zw5c2LBggVZlwEAHeWee+75VUT01zrXcUGwYMECjYyMZF0GAHQU2z+rd46uIQAoOIIAAAqOIACAgiMIAKDgCAIAKLiOu2sIAIpmaHRcG7fu0c8PHNRL+nq15vzFWrF0oGXfnyAAgBwbGh3Xus1jOjhxWJI0fuCg1m0ek6SWhQFdQwCQYxu37jkSAmUHJw5r49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/Ub2xdKGpK0KNuSjlb4IIiIcxudt32ZpLdKelMkHX5VxiVV/kU0NzmWal1Nfo/x5L+P2/66Spf9Mw6CFtTW9vfM9i9tnxoRjyXdBY/X+R7l9+xh29+VtFSlPvNWaubnL7fZZ/s4SS+Q9ESL65hWbRFRWceNKo2/5EEqv1czFRH/W/F4i+3P2p4TEXlZjI6uoUZsXyDpQ5KWR8TTdZrtlLTI9kLbx6s0sJfa3SbNsv082yeWH6s08F3zroYMZPGeDUt6d/L43ZKOuXKxfZLt5ySP50haJml3CrU08/NX1vsXkrbV+UOk7bVV9bsvl/RgG+pqxrCkS5O7h86S9FRFd2BmbL+4PL5j+wyVPnfbEerNy3q0Os9fkvaq1Od4b/JVvovjJZK2VLS7UNKPVPrL8co21PXnKvV//k7SLyVtra5Lpbs+7ku+drWjrmZry+g9O0XSdyT9WNK3JZ2cHB+UdGPy+A2SxpL3bEzS5SnWc8zPL+lalf7okKQTJH0t+R38b0kva8e/X5O1bUh+p+6TdJekV7aprlskPSZpIvkdu1zS+yS9LzlvSdcndY+pwR11ba7rior3a4ekN7Tr37LZL5aYAICCo2sIAAqOIACAgiMIAKDgCAIAKDiCAAAKjiAAgIIjCACg4AgCYIZs/2GyANsJyYzuXbZfk3VdQLOYUAa0gO2PqjQbuFfSvojYkHFJQNMIAqAFknV5dkr6rUpLCBzOuCSgaXQNAa1xiqTnSzpRpSsDoGNwRQC0QLK/8a2SFko6NSKuyLgkoGmF348AmCnbl0qaiIiv2O6R9H3b50TEtqxrA5rBFQEAFBxjBABQcAQBABQcQQAABUcQAEDBEQQAUHAEAQAUHEEAAAX3/yE6bEgygBu0AAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "x=torch.randn([50,1])#50个随机数 范围在0-1之间\n",
    "y=x*0.3+0.8\n",
    "\n",
    "plt.figure()\n",
    "plt.scatter(x,y)\n",
    "plt.xlabel('x')\n",
    "plt.ylabel('y')\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "class Lr(nn.Module):#继承nn.module\n",
    "    def __init__(self):\n",
    "        super(Lr,self).__init__()\n",
    "        self.linear=nn.Linear(1,1)\n",
    "        \n",
    "    def forward(self,x):\n",
    "        out=self.linear(x)\n",
    "        return out \n",
    "\n",
    "#实例化一个模型\n",
    "model=Lr()\n",
    "#实例化一个损失函数\n",
    "criteron=nn.MSELoss()\n",
    "#实例化一个优化器\n",
    "optimizer=optim.SGD(model.parameters(),lr=1e-3)#这里用SGD   "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/opt/conda/lib/python3.6/site-packages/torch/autograd/__init__.py:132: UserWarning: CUDA initialization: Found no NVIDIA driver on your system. Please check that you have an NVIDIA GPU and installed a driver from http://www.nvidia.com/Download/index.aspx (Triggered internally at  /pytorch/c10/cuda/CUDAFunctions.cpp:100.)\n",
      "  allow_unreachable=True)  # allow_unreachable flag\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "迭代次数: 0 \t误差 tensor(1.3629)\n",
      "迭代次数: 300 \t误差 tensor(0.4081)\n",
      "迭代次数: 600 \t误差 tensor(0.1227)\n",
      "迭代次数: 900 \t误差 tensor(0.0371)\n",
      "迭代次数: 1200 \t误差 tensor(0.0113)\n",
      "迭代次数: 1500 \t误差 tensor(0.0035)\n",
      "迭代次数: 1800 \t误差 tensor(0.0011)\n",
      "迭代次数: 2100 \t误差 tensor(0.0003)\n",
      "迭代次数: 2400 \t误差 tensor(0.0001)\n",
      "迭代次数: 2700 \t误差 tensor(3.6342e-05)\n",
      "迭代次数: 3000 \t误差 tensor(1.2299e-05)\n"
     ]
    }
   ],
   "source": [
    "for i in range(3001):\n",
    "    y_predict=model(x)#y的预测值\n",
    "    loss=criteron(y,y_predict)#计算loss\n",
    "    optimizer.zero_grad()#梯度清0\n",
    "    loss.backward()#反向传播\n",
    "    optimizer.step()#更新参数\n",
    "    if i%300==0:\n",
    "        print('迭代次数:',i,'\\t误差',loss.data)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYIAAAEGCAYAAABo25JHAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/Il7ecAAAACXBIWXMAAAsTAAALEwEAmpwYAAAedUlEQVR4nO3de5zVdb3v8ddnBoGGrBDY3nDW6BFLU9vbRtTstLWoyEryeDzBHrwTG9GTlZm4x0vHtIua+1IgkhdUVpp5ysMx2N6yrYUkYyqiKI40M6Iolx12dERg5nP++K01sy5zA9Zv/X5r/d7Px2Mes34Xmc8sYd7z+X1/3+/P3B0REUmumqgLEBGRaCkIREQSTkEgIpJwCgIRkYRTEIiIJNywqAvYWWPHjvWGhoaoyxARqShPPfXUJncf19exiguChoYGWlpaoi5DRKSimFl7f8d0aUhEJOEUBCIiCacgEBFJOAWBiEjCKQhERBJOQSAiknAKAhGRmEunoaEBamqCz+l0af98BYGISIyl0/D1r73L2e1Xsr+/Sns7zJxZ2jBQEIiIxNgzF97G5nfruJKr+DwPANDZCc3NpfsaFTezWEQkEbZsgdGjuS6zuYgmbmFGz+GOjtJ9KXUEIiJxc+21MHp0z+ZBvMLpLMo7pb6+dF9OHYGISFysXw/77de7ffHFpD92LW/OBDp7d9fVwTXXlO7LKghEROLgW9+Cf/7n3u033oC996Yps9ncHFwOqq8PQqCpqc8/ZZcoCEREotTaChMm9G5ffz1cdFHeKU1Npf3BX0hBICISlWnT4O67e7e3bIEPfrDsZWiwWESk3J5+Gsx6Q2DhQnCPJARAHYGISPl0d8MJJ8DjjwfbY8bAunUwcmSkZak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 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "model.eval()#进入评估模式\n",
    "predict=model(x)#模型的输出\n",
    "output=predict.detach().numpy()#转成数据准备画图\n",
    "\n",
    "plt.figure()\n",
    "plt.scatter(x,y,c='b')#原始的数据 蓝色\n",
    "plt.plot(x,output,c='r')#拟合的数据 红色\n",
    "plt.xlabel('x')\n",
    "plt.ylabel('y')\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
